<template>
    <div class="xangqin">
        <van-row>
            <van-col span="3" class="first"
                ><van-icon name="arrow-left" color="#fff" size="0.5rem"
            /></van-col>
            <van-col span="18"></van-col>
            <van-col span="3" class="last"> <span>...</span></van-col>
        </van-row>
        <div class="main">
            <img src="../../assets/shopcartimg/2.jpg" alt="" />
        </div>
        <div class="title">
            <div class="left">
                <div class="top" v-html="list.name">百纯布艺家具沙发</div>
                <div class="bottom" v-html="list.price">￥998——1180</div>
            </div>
            <div class="right"></div>
        </div>
        <div class="dis">
            <span v-html="list.dis1"
                >选择合适家中尺寸和形状，为每位家庭成员打造一个最可爱的角落</span
            >
            <br />
            <span v-html="list.dis2"
                >侧边触手可及的地方可存放遥控器，可防止遥控器埋在枕头和休闲毯下面</span
            >
        </div>
        <van-goods-action>
            <van-goods-action-icon icon="chat-o" text="客服" color="#ee0a24" />
            <van-goods-action-icon icon="cart-o" text="购物车" />
            <van-goods-action-icon icon="star" :text="text" :color="color" @click="collect" />
            <van-goods-action-button type="warning" text="加入购物车" />
            <van-goods-action-button type="danger" text="立即购买" @click="toshoplist" />
        </van-goods-action>
    </div>
</template>

<script>
import { 
    getgoodsinformation,
    getWhetherUserCollectGoods,
    UserCollectGoods,
    UserdeleteCollectGoods
 } from "../../api/index";
export default {
    data() {
        return {
            list: {},
            text:'收藏',
            color:'#eee',
            goodsId:''
        };
    },
    methods: {
        async init() {
            let obj = await getgoodsinformation({ id: this.goodsId });
            this.list = obj.data.data[0];
            let flag = await getWhetherUserCollectGoods({userId:this.$store.state.userId,goodsId:this.goodsId})
            if(flag.data) this.text = '已收藏' ,this.color = '#ff5000'
        },
        collect(){
            if(this.text == '已收藏') {
                this.text = '收藏',
                this.color = '#eee' 
                UserdeleteCollectGoods({userId:this.$store.state.userId,goodsId:this.goodsId})
            }
            else{this.text = '收藏',this.text = '已收藏',this.color = '#ff5000'
            UserCollectGoods({userId:this.$store.state.userId,goodsId:this.goodsId})
            }
        },
        toshoplist(){
            this.$store.commit('shoplist',this.list)
            this.$router.push({path:'confirmOrder'})
            // console.log(this.$store.state.shoplist);
        }
    },
    created() {

        this.goodsId = this.$store.state.xiangqinGoodsId
        this.init();
        // console.log(this.$store.state);
        
        
       
    },
};
</script>

<style scoped lang='less'>
.van-row {
    background-color: #ff5555;
    height: 100px;
    text-align: center;
    .first {
        height: 100px;
        line-height: 100px;
        // margin-top: 22px;
    }
    .last {
        margin-top: 10px;
        vertical-align: middle;
        color: white;
    }
}
.main {
    width: 100%;
    img {
        width: 100%;
        height: 600px;
    }
}
.title {
    margin-top: 20px;
    padding: 20px;
    box-sizing: border-box;
    .right .left {
        float: left;
    }
    .left {
        font-size: 40px;
        .bottom {
            color: red;
        }
    }
}
.dis {
    font-size: 30px;
    // margin-top: 20px;
    padding: 20px;
    box-sizing: border-box;
}
</style>  